<?php

namespace Org\Util\jiangyou2;

use Org\Util\ApiInterface;

class ApiServer implements ApiInterface
{
	public $apiUrl 	= '';

	public $timeout = 20;

	public $hospitalId = '';
    
    /**
     * @uses    实例化对象时设置参数
     * @param   $apiUrl        Api接口地址
     * @param   $hospitalId   医院key
     * @param   $timeout       超时时间
     * @author  Duanhy
     */
	function __construct($apiUrl , $hospitalId , $timeout = 10)
	{
		$this->apiUrl 	  = $apiUrl;
		$timeout && $this->timeout = $timeout;
		$this->hospitalId = $hospitalId;
	}

    /**
     * @uses    就诊卡查询和绑定
     * @param   $params 参数
     * +———————————————————————————+
     * user_name      用户名      
     * hospitalId     医院ID      
     * persion_id     用户卡号   
     * identy_id      未知（不使用）
     * type           未知（不使用） 
     * +———————————————————————————+
     * @author  Duanhy
     */ 
    public function cardInfoQueryAjax($params)
    {
        $user_name  = trim($params['user_name']);
        $person_id  = trim($params['person_id']);
        $hospitalId = $params['hospitalId'];
        $postData   = [ //参数数据封装
            'cardNo'        => '',
            'IdCode'        => $person_id,
            'patientId'     => '',
            'patientName'   => $user_name,
        ];
        $result = $this->Post($this->apiUrl.'getPatientInfo' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];
        if (!$user_name || trim($result['data'][0]['PatientName']) != $user_name) {
            return ['code' => 401 , 'status' => 2 , 'errorMsg'  => $result['msg'] ? $result['msg'] : '卡号验证失败！'];
        }
        $data   = [
            'sex'       => $result['data'][0]['sex'],    
            'phone'     => $result['data'][0]['phone'],
            'card_id'   => $result['data'][0]['patientId'],
            'identy_id' => $result['data'][0]['IdCard'],
            'UserIdKey' => $result['data'][0]['cardNo'],
        ];    
        return ['code' => 200 ,  'status' => 1 , 'errorMsg' => '卡号验证成功!' , 'data' => $data];
        
    }
	/**
	 * @uses 	门诊就诊科室查询
     * @param   $params
     * +———————————————————————————+
     * date         时间       
     * hospitalId   医院ID
     * period       未知（不使用）
     * time         时间戳（不使用）  
     * +———————————————————————————+
     * @author  Duanhy
	 */
	public function dutyDeptAjax($params)
	{
		$date 	= $params['date'];
		$IsAppt = strtotime(date('Y-m-d')) == strtotime($date) ? 1 : 0;
		$postData = [
			'IsAppt' 	=> 1,
			'opClassId' => '',
		];
		$result = $this->Post($this->apiUrl.'getOutDepaList' , __FUNCTION__ , $postData);	
		if ($result['code'] == 504) {
			return ['code' => 504];
		}
        $result = $result['data'];
		if (!$result['data']) {
			return ['code' => 401 , 'status'=> 2 , 'errorMsg' => $result['msg'] ? $result['msg'] : '访问失败!'];
		}
		$data 	= [];
		foreach ($result['data'] as $v) {
			$data[$v['DeptId']] = [
				'deptDutyId' 	=> $v['DeptId'],
				'deptId' 		=> $v['DeptId'],
				'title' 		=> $v['DeptName'],
			];
		}
		return ['code' => 200 ,  'status' => 1 , 'errorMsg' => '访问成功!' , 'data' => $data ];
		
	}


	/**
	 * @uses 门诊就诊科室医生查询
     * @param   $params
     * +———————————————————————————+
     * date         时间      
     * deptId       科室
     * cardId       卡号   
     * c_page       页码（不使用）
     * hospitalId   医院ID
     * period       未知（不使用）
     * time         时间戳（不使用）  
     * id           未知（不使用）
     * +———————————————————————————+
     * @author  Duanhy
     */
	public function dutyDoctorAjax($params)
	{
		$cardId = $params['cardId'];
		$deptId = $params['deptId'];
		$date 	= $params['date'];
		$IsAppt = strtotime(date('Y-m-d')) == strtotime($date) ? 1 : 0;
        $date   = '2016-07-15';
        $depetId = 6003;
        $cardId  = 
		$postData = [
			'Patientid' 	=> $cardId,
			'OpclassId'		=> '',
			'DeptId'		=> $deptId,
			'DoctID'		=> '',
			'startDate' 	=> $date,
			'endDate'	    => $date,
			'IsAppt' 		=> $IsAppt,

		];
		$result = $this->Post($this->apiUrl.'DoctRBList' , __FUNCTION__ , $postData);
		if ($result['code'] == 504) {
			return ['code' => 504];
		}
        $result = $result['data'];
		if (!$result['data']) {
			return ['code' => 401 , 'status' => 2 , 'errorMsg' => $result['msg'] ? $result['msg'] : '挂号失败'];
		}
		$data 	= [];
		foreach ($result['data'] as $v) {
			$data[] = [
				'profession'=> $v['RegType'],
				'name' 		=> $v['Doctname'],
                'docId' 	=> $v['Doctid'],
                'deptName' 	=> $v['DeptName'],
                'deptHisId' => $v['DeptId'],
                'rest' 		=> 0
			];
		}
		return ['code' => 200 , 'status' => 1 ,  'data' => $data , 'haveRest' => false];
	}


    /**
     * @uses 门诊就诊科室医生查询
     * @param   $params
     * +———————————————————————————+
     * date         日期      
     * time         时间(am)  
     * cardId       就诊卡号
     * deptHisId    医院科室ID
     * docHisId     医院医生ID
     * hospitalId   医院ID
     * +———————————————————————————+

     * @author  Duanhy
     */

    public function getDoctorSourceAjax($params) 
    {
        $date   = $params['date'];
        $time   = $params['time'];
        $cardId = $params['cardId'];
        $docHisId   = $params['docHisId'];
        $IsAppt = strtotime(date('Y-m-d')) == strtotime($date) ? 1 : 0;
        $postData   = [
            'Patientid'     => $cardId,
            'OpclassID'     => '',
            'DeptId'        => '',
            'DoctID'        => $docHisId,
            'startDate'     => $date,
            'endDate'       => $date,
            'IsAppt'        => $IsAppt,
        ];
        $result = $this->Post($this->apiUrl.'DoctRBList' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];
        if (!$result['data']) {
            return ['code' => 401 , 'status' => 2 , 'errorMsg' => isset($result['message'])?$result['message']:"访问异常！code:201"];
        }
        $data   = [];
        foreach ($result['data'] as $k => $v) {
            $data[] = [
                'RBASId'    => $v['RegisterId'],
                'range'     => $time,
                'date'      => $v['RegisterDate'],
                'treat_date'=> $v['RegisterDate'],
                'treat_time'=> '09:00:00',
                'fee'       => $v['SumFee'],
                'rest'      => $v['Remain'],
            ];
        }
        return ['code' => 200 , 'status' => 1 , 'data' => ['duty' => $data]];
    }
    /**
     * @uses    预约挂号提交
     * @param   $params
     * +———————————————————————————+
     * RbasId       唯一标识
     * act          锁号
     * cardId       就诊卡号
     * date         日期
     * deptHisId    医院科室ID
     * docHisId     医院医生ID
     * fee          付款金额
     * hospitalId   医院ID
     * 'period' => 'am',
     * userName     用户姓名
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function registrationAjax($params)
    {
        return [
            'code'      => 200,
            'status'    => 1,
            'errorMsg'  => '操作成功',
            'data'      => [
                'apptId'    => $params['RbasId'],
                'fee'       => $params['fee'], 
            ],
        ];
    }

	/**
	 * @uses 支付后进行挂号
	 * @param   $params
     * +———————————————————————————+
     * date         时间      
     * ApptId       科室
     * cardNo       卡号   
     * +———————————————————————————+
     * @author  Duanhy
     */
	public function registrationFetchAjax($params)
    {
        $date 		= $params['date']; 
        $ScheduleCd = $params['ApptId']; 
        $postData 	= [
        	'Patientid' 	=> $params['cardNo'],
        	'RegisterId'	=> $params['ApptId'],
        ];     
        $result = $this->Post($this->apiUrl.'opAvisit' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
			return ['code' => 504];
		}
		$result = $result['data'];
        if(!$result['data'][0]){
            return [
				'code' 		=> 401 , 
                'status'    => 2,
				'errorMsg' 	=> isset($result['msg']) ? $result['msg'] : '访问异常！code:201',
			];
        }
        $result = $result['data'][0];
        $time 	= strtotime($date);
        $year 	= date('Y' , $time);
        $month 	= date('m' , $time);
        $day 	= date('d' , $time);
        $data 	= [
        	'RegYear' 	=> $year,                           
        	'RegMonth'  => $month,                                 
        	'RegDay' 	=> $day, 
        	'date' 		=> $date,
        	'appId' 	=> $ScheduleCd,
        	'queueNo' 	=> $result['AvisitId'],
        	'address' 	=> $result['address'],
        	'regType' 	=> '普通门诊',
        	'LocInfo' 	=> '江油市第二人民医院',
        	'fee' 		=> $result['Amount'],
        	'invoiceNo' => $result['AvisitId'],
            'status'     => 1,
        	'TimeInfo' 	=> '请于'.$year.'年'.$month.'月'.$day.'日'.$result['TimeInfo'].'前来就诊',

        ];
        return ['code' => 200 , 'status' => 1 , 'data' => $data];
    }	

    /**
     * @uses 取消预约 （锁号未支付） 定时任务
     * @param   $params
     * +———————————————————————————+
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function cancelRegistrationAjax($params)
    { 
        $postData   = [
            'AvisitId'     => 160708000008,
        ];     
        $result = $this->Post($this->apiUrl.'cancelAvisit' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];
        if(!$result['data']){
            return [
                'code'      => 401 ,
                'status'    => 2 , 
                'errorMsg'   => isset($result['message']) ? $result['message'] : '访问异常！code:201',
            ];
        }
    }
    /*****************************门诊*****************************/
    /**
     * @uses 门诊缴费列表
     * @param   $params
     * +———————————————————————————+
     * cardId       卡号   
     * hospitalId   医院ID
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function doctorAdviceAjax($params){
        $hospitalId = $params['hospitalId'];
        $identy_id  = $params['cardId'];         //组装进行访问接口
        $postData   = [
            'VisitId'   => '',
            'BeginDate' => '',
            'endDate'   => '',
            'patientId' => $identy_id,
            'BillNO'    => '',
        ];
        $result = $this->Post($this->apiUrl.'getChargeList' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];
        if (!$result['data']) {
            return ['code' => 401 , 'status' => 2 , 'errorMsg' => $result['msg'] , 'data' => []];
        }
        foreach ($result['data'] as $v) {
            $type = in_array($v['BillType'] , [1 , 2]) ? 1 : 0;
            if (in_array($v['BillNO'] , $data_recipeId)) {
                $data['payList'][$v['BillNO']]['fee']   = $data['payList'][$v['BillNO']]['fee'] + $v['BillSum'];
            } else {
                $data['payList'][$v['BillNO']]  = [
                    'recipeId'      =>$v['BillNO'],
                    'orderNumber'   =>$v['VisitID'],
                    'fee'           =>$v['BillSum'],
                    'payDate'       =>date('Y-m-d' , strtotime($v['BillTime'])),
                    'type'          =>$type,
                ];
            }
        }
        return ['code' => 200 , 'status' => 1 , 'errorMsg' => $result['msg'] , 'data' => $data];
    }

    /**
     * @uses    生成门诊缴费订单
     * @param   $params
     * +———————————————————————————+
     * orderNum     挂号码      
     * recipeId      
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function preGeneratePayOrderAjax($params)
    {
        $visitid    = $params['orderNum'];
        $billno     = $params['recipeId'];
        $postData   = [
            'VisitId'   => $visitid,
            'BeginDate' => '',
            'endDate'   => '',
            'patientId' => '',
            'BillNO'    => '',
        ];
        $result = $this->Post(self::$apiUrl.'getChargeList' , __FUNCTION__ , $postData);
        $result = $result['data'];
        foreach ($result['data'] as $v) {
            if ($v['BillNO'] == $billno && $v['PayFlag'] == 0) {
                $data['Doctid']     = $v['Doctid'];
                $data['doctorName'] = $v['Doctname'];
                $data['execLoc']    = '';
                $data['PayFlag']    = $v['PayFlag'];
                $data['payDate']    = $v['BillTime'];
                $data['recipeId']   = $billno;
            }
        }
        if ($data['PayFlag']) {
            return ['code' => 401 , 'status' => 2 , 'errorMsg' => '无效订单'];
        }
        $postData   = [
            'Doctid' => $data['Doctid'],
            'deptId' => '',
        ];
        $result = $this->Post($this->apiUrl.'getDocInfo' , __FUNCTION__ , $postData);
        $result = $result['data'];
        $docter = current(current($result));
        $data['deptName']   = $result['Doctgender'];
        $postData   = [
            'VisitId'   => $visitid,
            'BillNO'    => $billno,
        ];
        $result = $this->Post($this->apiUrl.'getChargeInfo' , __FUNCTION__ , $postData);
        $result = $result['data'];
        if (!$result['data']) {
            return ['code' => 401 , 'status' => 2 , 'data' => []];
        }
        $fee    = 0;
        foreach ($result['data'] as $v) {
            $c_data = [
                'items'     => [
                    [
                        'itemName'      => $v['ITEM_NAME'],
                        'Specs'         => $v['SPECS'],
                        'unit'          => doubleval($v['PRICE_UNIT']),
                        'fee'           => doubleval($v['UNIT_PRICE']),
                        'quantity'      => doubleval($v['QTY']),
                        'Prescription'  => $billno,
                    ],
                ],
                'cateFee' => doubleval($v['OWN_COST']),
            ];
            $fee += doubleval($v['OWN_COST']);
        }
        return ['code' => 200 , 'status' => 1 , 'data' => $data];
    }

    /**
     * @uses    缴费生成订单
     * @param   $params 
     * @author  Duanhy
     */
    public function GeneratePayOrderAjax($params) {
       
    }
    /**
     * @uses    门诊支付提交
     * @param   $params
     * +———————————————————————————+
     * hospitalId         时间      
     * orderNumber        科室
     * cardNo             卡号   
     * transaction_id     医院ID
     * fee          
     * medicineRetrun
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function outPatientPayAjax($params)
    {

        $hospitalId     = $params['hospitalId'];
        $order_number   = $params['orderNumber'];
        $cardNo         = $params['cardNo'];
        $transaction_id = $params['transaction_id'];
        $fee            = $params['fee'];
        $medicineRetrun = $params['medicineRetrun'];
        $medicineRetrun = json_decode($medicineRetrun , true);
        $billno         = $medicineRetrun['recipeId'];
        //获取基础信息
        $postData       = [
            'visitId'   => $order_number,
            'billno'    => $billno,
            'patientId' => $cardNo,
            'amount'    => $fee,
            'termid'    => '',
            'optId'     => '',
            'paySerNo'  => $transaction_id,
            'payType'   => 1,
        ];
        $result = $this->Post($this->apiUrl.'doPay',__FUNCTION__,$postData);
        $result = $result['data'];
        if (!$result['data'] || $result['data']['ret'] != 1) {
            return ['code' => 401 , 'status' => 2 , 'errorMsg' => $result['msg']];
        } 
        return ['code' => 200 , 'status' => 1 , 'data' => []];
    }

    
    /***************************住院****************************/

    /**
     * @uses    住院缴费列表
     * @param   $params
     * +———————————————————————————+
     * identy_id    时间       
     * hospitalId   医院ID
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function getPayInfoAjax($params)
    {
        $hospitalId = $params['hospitalId'];

        //组装进行访问接口
        $data['hos_code'] = $this->checkHospital($hospitalId);
        $data['identy_id'] = $params['identy_id'];
        $data['token'] = $this->token;

        $params = array();
        $params['bs_code'] = 'S_06035';
        $params['reqData'] = json_encode($data);    

        $result = $this->Post($this->apiUrl , __FUNCTION__ , $params);
        return ['code' => 200 , 'data' => $result];
    }

    /**
     * @uses    预交费生成订单
     * @param   $params
     * +———————————————————————————+ 
     * hospitalId   医院ID
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function createPayOrderAjax($params)
    {
        $hospitalId = $params['hospitalId'];   

        $postData   = [
            'bs_code'   => 'T_02042',
            'reqData'   => json_encode($data),
        ];
        $result = $this->Post($this->apiUrl , __FUNCTION__ , $postData);
        $result = $result['data'];
        return ['code' => 200 , 'data' => $result];
        //组装进行访问接口
        $data['hos_code'] = $this->checkHospital($hospitalId);
        $data['identy_id'] = $_POST['params'];
        $data['pay_type'] = '30';
        $data['agent_identy_id'] = $_POST['identy_id'];
        $data['pay_fee'] = $_POST['pay_fee'];
        $data['token'] = $this->token;
        $data['pay_channel'] = $this->pay_channel;

        
    }   

    /**
     * @uses    检查订单是否可以支付
     * @param   $params
     * +———————————————————————————+    
     * identy_id       科室
     * order_number       卡号   
     * hospitalId   医院ID
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function checkOrderAjax($params)
    {
        $hospitalId = $params['hospitalId'];
        //组装进行访问接口
        $data['hos_code'] = $this->checkHospital($hospitalId);
        $data['identy_id'] = $params['identy_id'];
        $data['order_number'] = $params['order_number'];
        $data['token'] = $this->token;
        $data['pay_channel'] = $this->pay_channel;

        $params = array();
        $params['bs_code'] = 'S_02011';
        $params['reqData'] = json_encode($data);

        $result = $this->Post($this->apiUrl , __FUNCTION__ , $params);
        $result = $result['data'];
        return ['code' => 200 , 'data' => $result];
    }

    /**
     * @uses    提交订单
     * @param   $params
     * +———————————————————————————+
     * transaction_id         时间      
     * order_number           科室
     * identy_id              卡号   
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function prePayOrderSubmitAjax($params)
    {
        $transaction_id = $params['transaction_id'];
        //提交订单
        $result = $this->orderSubmit($params['order_number'], $params['identy_id'], $transaction_id);
        return ['code' => 200];
    }

    /**
     * @uses    检验报告列表
     * @param   $params
     * +———————————————————————————+
     * cardNo       就诊卡号      
     * c_page       页码
     * hospitalId   医院ID
     * user_name    用户姓名
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function myExamineReportAjax($params)
    {
        //获取基础信息
        $postData   = [
            'patientId'     => $params['cardNo'],
            'CheckId'       => '',
            'BeginDate'     => '',
            'EndDate'       => '',
        ];
        $result = $this->Post($this->apiUrl.'getLis' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];
        if (!$result['data']) {
            return ['code' => 401 , 'status' => 2 , 'data' => []];
        }
        $temp   = [];
        $currentMonth   = date('Y-m-01 00:00:00');
        foreach ($result['data'] as &$v) {
            $v['item_name']     = $v['checkName'];
            $v['report_date']   = date('Y-m-d' , strtotime($v['ReportDate']));
            $v['inspec_no']     = $v['checkId'];
            $v['archive_date']  = $v['checkDate'];
            if ($v['ReportDate'] > $currentMonth ) {
                $temp['currentMonth'][] = $v;
            } else {
                $temp['preMonth'][]     =  $v;
            }
        }
        return ['code' => 200 , 'status' => 1 , 'data' => $temp];
    }

    /**
     * @uses    检验报告详情
     * @param   $params
     * +———————————————————————————+
     * inspec_no         时间      
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function myExamineReportResultAjax($params)
    {
        $CheckId    = $params['inspec_no'];

        $postData   = [
            'patientId' => '',
            'CheckId'   => $CheckId,
            'BeginDate' => '',
            'EndDate'   => '',
        ];
        $result = $this->Post($this->apiUrl.'getLis' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];

        $report_basics=$result['data'][0];
        if ($report_basics) {
             $data['type']  = 2;//报告类型
             $data['user_name'] =$report_basics['patientName'];//姓名
             $data['exam_item'] =$report_basics['checkName'];//检查项目
             $data['exam_no']   =$report_basics['checkId'];//检查报告编号
             $data['report_date']   =$report_basics['ReportDate'];//报告日期
             $data['check_date']    =$report_basics['checkDate'];//检查日期
        }    
        $postData   = [
            'CheckId'   => $CheckId,
            'itemNo'    => '',
            'itemName'  => '',
        ];
        $result = $this->Post($this->apiUrl.'GetLisDetail' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];
        if (!$result['data']) {
            return ['code' => 401 , 'status' => 2 , 'data' => []];
        }
        foreach ($result['data'] as $key => $value) {
            $data['item'][] = [
                'exam_item'     => $value['itemName'],//项目
                'diagno_result' => $value['reportResult'],//结果
                'unit'          => $value['itemUnit'],//单位
                'ref_range'     => $value['itemRage'],//参考值
                'reportDesc'    => $value['reportDesc'],//结果描述
             ];
        }
        return ['code' => 200 , 'status' => 1 , 'data' => $data];
    }
        
    /* @uses    检查报告列表
     * @param   $params
     * +———————————————————————————+
     * cardNo       就诊卡号
     * hospitalId   医院ID
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function myInspectReportAjax($params)
    {
        $postData   = [
            'patientId' => $params['cardNo'],
            'CheckId'   => '',
            'BeginDate' => '',
            'EndDate'   => '',
        ];

        $result = $this->Post(self::$apiUrl.'getLis' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];
        if (!$result['data']) {
            return ['code' => 401 , 'status' => 2 ,  'data' => []];
        }
        $temp   = [];
        $currentMonth   = date('Y-m-01 00:00:00');
        foreach ($result['data'] as &$v) {
            $v['item_name']     = $v['checkName'];
            $v['report_date']   = date('Y-m-d', strtotime($v['ReportDate']));
            $v['inspec_no']     = $v['checkId'];
            $v['archive_date']  = $v['checkDate'];
            if($v['ReportDate'] > $currentMonth ){
                $temp['currentMonth'][] = $v;
            }else{
                $temp['preMonth'][]     =  $v;
            }
        }
        return ['code' => 200 , 'status' => 1 , 'data' => $temp];
    }

    /**
     * @uses    检查报告详情
     * @param   $params
     * +———————————————————————————+
     * inspec_no         时间      
     * +———————————————————————————+
     * @author  Duanhy
     */
    public function myInspectReportResultAjax($params)
    {
        $CheckId    = $params['inspec_no'];

        $postData   = [
            'patientId' => '',
            'CheckId'   => $CheckId,
            'BeginDate' => '',
            'EndDate'   => '',
        ];
        $result = $this->Post($this->apiUrl.'getLis' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];

        $report_basics=$result['data'][0];
        if ($report_basics) {
             $data['type']  = 2;//报告类型
             $data['user_name'] =$report_basics['patientName'];//姓名
             $data['exam_item'] =$report_basics['checkName'];//检查项目
             $data['exam_no']   =$report_basics['checkId'];//检查报告编号
             $data['report_date']   =$report_basics['ReportDate'];//报告日期
             $data['check_date']    =$report_basics['checkDate'];//检查日期
        }    
        $postData   = [
            'CheckId'   => $CheckId,
            'itemNo'    => '',
            'itemName'  => '',
        ];
        $result = $this->Post($this->apiUrl.'GetLisDetail' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result = $result['data'];
        if (!$result['data']) {
            return ['code' => 401 , 'status' => 2 , 'data' => []];
        }
        foreach ($result['data'] as $key => $value) {
            $data['item'][] = [
                'exam_item'     => $value['itemName'],//项目
                'diagno_result' => $value['reportResult'],//结果
                'unit'          => $value['itemUnit'],//单位
                'ref_range'     => $value['itemRage'],//参考值
                'reportDesc'    => $value['reportDesc'],//结果描述
             ];
        }
        return ['code' => 200 , 'status' => 1 , 'data' => $data];
    }
        
    

    /**
     * @uses    HIS对账接口
     * @param   $params
     * +———————————————————————————+
     * checkDate        日期      
     * +———————————————————————————+
     * @author  Duanhy
     */
   	public function BanlanceToWeixinAjax($params)
   	{
   		$date       = date('Y.m.d',strtotime($params['checkDate']));
        $postData   = ['date' => $date];
        $result     = $this->Post(self::$apiUrl.'bill' , __FUNCTION__ , $postData);
        if ($result['code'] == 504) {
            return ['code' => 504];
        }
        $result     = $result['data'];
        if (!$result['data']) {
            return ['code' => 401 , 'status' => 2];
        }

        //数组元素转换
        foreach ($result['data'][0]['balances'] as $k=>$v) {
            $result['data'][0]['balances'][$k]['transaction_id'] = $v['bank_no'];
        }
        return ['code' => 200 , 'status' => 1 , 'data' => $result['data'][0]['balances']];
   	}

    /**
     * @uses    http curl远程访问
     * @param   $url 远程调用地址
     * @param   $method 访问本地方法名
     * @param   $post   参数
     * @author  Daunhy
     * @since   2016-07-04
     */
	protected function Post($url , $method , $post = null) 
	{  
        if (!is_array($post)) {
            return ['code' => 400];
        }
        $strIn 	= json_encode($post , JSON_UNESCAPED_UNICODE); //json 中文不编码
        $ch 	= curl_init($url . '?strIn='.$strIn); 
        curl_setopt($ch , CURLOPT_RETURNTRANSFER , true);  
        curl_setopt($ch , CURLOPT_BINARYTRANSFER , true); 
        curl_setopt($ch , CURLOPT_TIMEOUT , $this->timeout);
        $result 	= curl_exec($ch); 
        $httpCode   = curl_getinfo($ch , CURLINFO_HTTP_CODE);
        curl_close($ch); 
        if ($httpCode !== 200) {
            return ['code' => 504];
        }
        $search     = [
            '<?xml version="1.0" encoding="utf-8"?>'."\r\n".'<string xmlns="http://tempuri.org/">',
            '</string>',
            '\'',
        ];
        $replace    = ['' , '' , '"'];
        $resultJson = str_replace($search , $replace , $result);
        $result     = json_decode($resultJson , true);
        if (C('LOG_PATH_TYPE') == 1) {
            $fileContent    = [
                'hospitalId'=> C('KEY'),
                'type'      => '1',
                'params'    => $strIn,
                'return'    => $resultJson,
            ];
            \Common\Model\LogModel::setLog(json_encode($fileContent));
        } else {
            $fileContent    = var_export($strIn , true)."\r\n".$resultJson."\r\n".var_export($result , true);
            $dir = "Log/".C('FOLDER_NAME')."/".C('AJAX_LOG_PATH')."/".date("Y-m-d")."/".$method."/";
            $filename = date("H_i_s")."_".rand(10000, 99999);
            writeLog($dir , $filename , $fileContent);
        }
        return ['code' => 200 , 'data' => $result];
        
    }


}